package com.smart.utils;


import cn.dev33.satoken.stp.StpUtil;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.domain.AclMeta;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class WorkAcl {


    /**
     * 生成喂养令牌标识
     *
     * @param loginId 登录id
     * @return {@code String}
     */
    public static String login(Long loginId) {
        WorkStp.login(loginId, 60 * 60 * 24 * 15);
        return WorkStp.getTokenInfo().getTokenValue();
    }


    /**
     * 得到获得喂养的TokenId
     *
     * @return {@link Long}
     */
    public static Long getLoginId() {
        return WorkStp.getLoginIdAsLong();
    }

    /**
     * 注销登录
     */
    public static void loginOut(Long WorkId) {
        WorkStp.logout(WorkId);
    }


    /**
     * 是否是喂养管理员
     * @return {@link Boolean}
     */
    public static Boolean getIsManage() {
        if (WorkStp.isLogin()){
            return  (Boolean) WorkStp.getSession().get(SmartConstant.WORK_SESSION_CODE);
        }
        return false;
    }

    /**
     * 设置管理员
     * @param manage 管理员
     */
    public static void setIsManage(Boolean manage) {
        WorkStp.getSession().set( SmartConstant.WORK_SESSION_CODE, manage );
    }

}
